import React, { Component } from 'react'

export default class NotControlForm extends Component {

    state = {
        user:'',
        pass:''
    }
  render() {
    return (
      <div>
        <h2>登录</h2>
        <hr />
        <form action="">
            用户名:<input  type="text" value={this.state.user} onChange={this.saveUser}/>
            登录:<input type="password" value={this.state.pass} onChange={this.savePass}></input>
            <button onClick={this.login}>登录</button>
            <button onClick={this.result}>清空</button>
        </form>
      </div>
    )
  }
  login = (e)=>{
    e.preventDefault()
    console.log(`账号为${this.state.user},密码为${this.state.pass}`);
    
  }

  result = (e)=>{
    e.preventDefault()
    this.setState({
        user:'',
        pass:''
    })
  }
  saveUser = (e)=>{
    this.setState({
        user:e.target.value
    })
  }

  savePass = (e)=>{
    this.setState({
        pass:e.target.value
    })
  }
}
